package org.autumn.review.thread;

public class CachePadding {

    // 要求线程中可见, 会刷新主存
    public volatile static long[] arr = new long[16];
    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(() -> {
            for (long i = 0; i < 10_0000_0000L; i++) {
                arr[0] = i;
            }
        }, "t1");


        Thread t2 = new Thread(() -> {
            for (long i = 0; i < 10_0000_0000L; i++) {
                arr[8] = i;
            }
        }, "t2");
        long start = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(System.currentTimeMillis() - start);

    }
}
